<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">

						<div class="layui-card-body">

							<div class="layui-row layui-col-space15">

								<div class="layui-btn-sm12 layui-col-md12 layui-col-xs12">
									<!-- 搜索 -->
									<!-- <form class="layui-form search" id="form" onsubmit="return false" action="##">
										<div class="layui-inline search_inline">
											<label class="layui-form-label">店铺状态：</label>
											<div class="layui-input-inline">
												<select name="status" class="on_off" lay-filter='goods_status'></select>
											</div>
										</div> 
										
					
										<div class="layui-inline search_inline">
											<label class="layui-form-label">店铺名称：</label>
											<div class="layui-input-inline">
												<input class="layui-input" lay-verify="" name="keyword" placeholder="店铺名称"
													autocomplete="off">
											</div>
										</div>
										<button class="layui-btn search_inline" lay-submit="" lay-filter="search"
											data-type="reload">搜索</button>
										<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
									</form> -->
									<!-- 搜索 -->
									<table id="test-table-operate" lay-filter="test-table-operate"></table>

									<script type="text/html" id="test-table-operate-barDemo">
										<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">移除</a>
									</script>
								</div>
							</div>
						</div>

					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">确定</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script type="text/html" id="zizeng">
		{{d.LAY_TABLE_INDEX+1}}
		</script>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				video_id: getParam('id'),
				shopid: localStorage.getItem('pxy_shopid')
			}
			var tableIns;
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'tree', 'form', 'laytpl', 'laydate', 'layedit', 'upload'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form,
					tree = layui.tree,
					table = layui.table;
				var shop_copartner_record = null

				initdata();

				function initdata() {
					tableIns = table.render({
						elem: '#test-table-operate',
						url: server.sys_shop_video_put_in_list,
						height: 'full-150',
						//totalRow: true,
						cols: [
							[
								{
									field: 'status',
									title: '状态',
									templet: function(d) {
										var html = ''
										if (d.status == 1) {
											html = '投放'
										}else if(d.status == 2){
											html = '结束投放'
										} else {
											html = ''
										}
										return html;
									}
								}, {
									field: 'once_give_score',
									title: '观看奖励'
								}, {
									field: 'hav_give_score',
									width: 120,
									title: '已奖励积分'
								}, {
									field: 'return_give_score',
									width: 120,
									title: '返回积分'
								}, {
									field: 'total_give_score',
									width: 120,
									title: '总投放积分'
								}, {
									field: 'remark',
									title: '备注'
								}
							]
						],
						page: false,
						where: _data,
						limit: limit,
						limits: limits,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							shop_copartner_record = res.shop_video_put_in_record.data
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								//"count": res.shop.pager.total, //解析数据长度
								"data": res.shop_video_put_in_record.data //解析数据列表
							};
						},
						done: function() {
							//lay-tree的颜色 
							var nodes = document.getElementsByClassName("layui-tree-txt");
							for (var i = 0; i < nodes.length; i++) {
								if (nodes[i].innerHTML === _data.name)
									nodes[i].style.color = "red";
								else
									nodes[i].style.color = "#555";
							}
						},
					});
				}

				//				truly_log_status_show('radio');
				form.on('submit(demo1)', function(data) {
					parent.layer.closeAll();
				});

				function submitdata(_url) {
					// alert(10);/*  */
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					//var data = obj.data;
					if (obj.event === 'del') {
						var Data = table.cache["test-table-operate"];
						Data.splice(obj.tr.data('index'), 1) //根据索引删除当前行
						tableIns.reload({
							data: Data
						});
						// var data = obj.data;
						// console.log(data)
						// var id = data.shopid
						// var lock = false
						// layer.confirm('确定要移除该店铺？', function(index) {
						// 	if (!lock) {
						// 		lock = true
						// 		//submitDelete(id, 0)
						// 	}
						// }, function() {
						// 	initdata();
						// 	layer.msg('取消操作');
						// });

					}
				});

				//事件
				var active = {
					batchdel: function() {

					},
					addshop: function() {
						// layer.open({
						// 	type: 1,
						// 	title: '选择店铺',
						// 	shadeClose: false,
						// 	shade: 0.5,
						// 	area: ['900px', '800px'],
						// 	content: 'choose_shop.html',
						// 	end: function() {}
						// });
						// layer.open({
						// 	type: ,
						// 	title: '划拨店铺',
						// 	shadeClose: false,
						// 	shade: 0.5,
						// 	maxmin: true, //开启最大化最小化按钮
						// 	area: ['90%', '90%'],
						// 	content: 'choose_shop.html',
						// 	success: function(layero, index) {
						// 		var iframe = window['layui-layer-iframe' + index]
						// 		iframe.child(_data, index)
						// 	},
						// 	end: function() {}
						// });
					},
					on: function() {
						edit_status(1, "启用")
					},
					off: function() {
						edit_status(0, "禁用")
					},
				}
				$('.table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				$("#chooseShop").bind("click", function(e) {
					chooseShop();
				});
			});
			window.chooseShop = function() {
				layer.open({
					type: 2,
					title: '选择店铺',
					shadeClose: false,
					shade: 0.5,
					maxmin: false, //开启最大化最小化按钮
					area: ['90%', '90%'],
					content: 'choose_shop.html',
					end: function() {

					},
					success: function(layer, index) {}
				});
			}
			window.selectShop = function(data) {
				if (data && data.length) {
					for (var p in data) {
						tableActive.addNewRow(data[p]);
					}

				}
			}

			window.delgoods = function(obj, id) {
				layer.confirm('确定要删除商品？', function(index) {
					if (id) {
						var row = $('#' + id);
						var rowdata = JSON.parse(unescape(row.attr("rowdata")));
						if (rowdata.seckill_id && rowdata.id) {
							$.ajax({
								url: server.seckill_goods_delete,
								type: 'post',
								dataType: 'json',
								data: "id=" + rowdata.id,
								success: function(data) {
									if (data.code == '0') {
										row.remove();
										layer.close(index)
										layer.msg('删除成功');
									} else {
										layer.msg('删除失败');
									}
								},
								'error': function() {
									layer.close(index)
									layer.msg('系统错误');
								}
							})
						} else {
							row.remove();
							layer.close(index)
						}
					}
				}, function() {
					layer.msg('取消操作');
				});

			}

			//定义表格操作
			var tableActive = {
				//添加行
				addNewRow: function(newRow) {
					//获取表格当前数据
					var oldData = layui.table.cache['test-table-operate'];
					//新行数据
					// var newRow= {
					// 	id: id,
					// 	name: name,
					// 	gender: gender,
					// 	age: age,
					// 	grade: grade
					// };
					//将新行插入表格数据中
					oldData.push(newRow);
					//如果原table渲染时指定了数据url
					//重载时需要设置url: null
					//使用新数据重载表格
					tableIns.reload({
						url: null,
						data: oldData
					});
				},
				//删除行
				deleteRow: function() {
					var oldData = layui.table.cache['test-table-operate'];
					for (var i = 0, row; i < oldData.length; i++) {
						row = oldData[i];
						//在table工具栏监听时删除对应行dom结构
						//行不存在则从数据中删除
						if (!row || !row.id) {
							oldData.splice(i, 1); //删除一项
						}
						continue;
					}
					tableIns.reload({
						url: null,
						data: oldData
					});
				},
				//更新数据
				updateRow: function(data) {
					//更新表数据
					var oldData = layui.table.cache['test-table-operate'];
					for (var i = 0, row; i < oldData.length; i++) {
						row = oldData[i];
						if (row.id == data.id) {
							$.extend(oldData[i], data);
							continue;
						}
					}
					tableIns.reload({
						url: null,
						data: oldData
					});
				}
			};
		</script>
	</body>

</html>